<?php
/**
 * Created by PhpStorm.
 * User: KHACHUNG
 * Date: 3/24/14
 * Time: 7:14 PM
 */
class IndexsController extends AppController{
    var $name='Indexs';
    function index(){

        $this->loadModel('Dethi');
        $this->loadModel('Cauhoi');
        $this->loadModel('User');
        $this->set('dethi_choduyet',$this->Dethi->count_choduyet());
        $this->set('tongdethi',$this->Dethi->find('count'));
        $this->set('cauhoi_choduyet',$this->Cauhoi->find('count',array('conditions'=>array('trangthai'=>'0'))));
        $this->set('tongcauhoi',$this->Cauhoi->find('count'));
        $this->set('topuser',$this->selecttopuser());

    }
    function selecttopuser(){
        $dem=$this->Cauhoi->topuser();
        @$top1=$dem[0];
        @$top2=$dem[1];
        @$top3=$dem[2];
        @$tong=$top1[0]['tongcau'] + $top2[0]['tongcau']+ $top3[0]['tongcau'];
        @$top=array('top1'=>array('username'=>$this->User->getname($top1['cauhois']['users_id']),'socau'=>$top1[0]['tongcau'],'tongcau'=>$tong),
                    'top2'=>array('username'=>$this->User->getname($top2['cauhois']['users_id']),'socau'=>$top2[0]['tongcau'],'tongcau'=>$tong),
                    'top3'=>array('username'=>$this->User->getname($top3['cauhois']['users_id']),'socau'=>$top3[0]['tongcau'],'tongcau'=>$tong)

        );
        return $top;
    }
}